@use 'sass:map';

@use './shared' as *;
@use './design' as *;

$scroll: () !default;
$scroll: map.merge(
  (
    move-duration: 180ms,
    move-timing: cubic-bezier(0.165, 0.84, 0.44, 1)
  ),
  $scroll
);

.#{$namespace}-scroll {
  &-vars {
    @include define-preset-values('scroll', $scroll);
  }

  @include basis;
  @include inherit-color;

  position: relative;
  overflow: hidden;

  &__wrapper {
    position: relative;
    vertical-align: top;
    will-change: transform;
    transition-timing-function: get-css-var('scroll-move-timing');
    transition-duration: get-css-var('scroll-move-duration');
    transition-property: transform;

    @include clear-both;
  }

  $wrap: #{&}__wrapper;

  &--scrolling,
  &--using-bar,
  &--no-ready,
  &--no-transition {
    & > #{$wrap} {
      transition-duration: 0ms;
    }
  }

  &--no-ready {
    & > #{$wrap} {
      display: inline-block;
    }
  }

  // 与使用 js 找到所有子元素再添加样式相比效率如何 (不太好测试) ?
  &--scrolling,
  &--using-bar {
    & > #{$wrap} > * {
      pointer-events: none;
    }
  }

  &--horizontal,
  &--both {
    & > #{$wrap} {
      display: inline-block;
    }
  }

  &__extra {
    position: absolute;
    inset-inline-start: 0;
    top: 0;
    width: 100%;
    height: 100%;

    & > * {
      position: relative;
      z-index: 10;
    }
  }

  &--both > &__bar--horizontal {
    width: calc(100% - get-css-var('scrollbar-width') + 1px);
  }

  &--both > &__bar--vertical {
    height: calc(100% - get-css-var('scrollbar-width') + 1px);
  }
}
